package com.gec.zhs.utils;

import lombok.Data;

/**
 * @author zhs
 * @version 1.0
 * @date 2025-08-25
 * @description
 */
@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    private static <T> Result build(T data) {
        Result<T> tResult = new Result<>();
        if (data != null) {
            tResult.setData(data);
        }
        return tResult;
    }

    public static <T> Result build(T data, ResultCodeEnum resultCodeEnum) {
        Result<T> tResult = build(data);
        tResult.setCode(resultCodeEnum.getCode());
        tResult.setMsg(resultCodeEnum.getMsg());
        return tResult;
    }

    public static <T> Result build(Integer code, String msg, T data) {
        Result<T> tResult = build(data);
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }

    public static <T> Result build(Integer code, String msg) {
        Result<T> tResult = build(null);
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }

    public static<T> Result ok(T data){
        return build(data, ResultCodeEnum.SUCCESS);
    }

    public static Result ok(){
        return ok(null);
    }

    public static Result fail(ResultCodeEnum resultCodeEnum){
        return build(resultCodeEnum);
    }

    public static<T> Result fail(T data){
        return build(data, ResultCodeEnum.FAIL);
    }

    public static Result fail(Integer code, String msg){
        return build(code, msg);
    }
    public static Result fail(){
        return fail(null);
    }

    public Result<T> message(String msg){
        this.setMsg(msg);
        return this;
    }

    public Result<T> code(Integer code){
        this.setCode(code);
        return this;
    }


}
